package io.easyspring.common.generator.builder;

import io.easyspring.common.generator.config.GeneratorOutputDirConfig;
import io.easyspring.common.generator.support.FileOutParameter;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件配置参数的 Builder 工具类
 *
 * @author summer
 * @version V1.0.0-RELEASE
 * DateTime 2019-05-11 20:51
 */
public class FileOutParameterBuilder {

    /**
     * 模板路径常量
     */
    private static final String MODEL_TEMPLATE = "/templates/entity.java.vm";

    private static final String SERVICE_TEMPLATE = "/templates/service.java.vm";
    private static final String SERVICE_IMPL_TEMPLATE = "/templates/serviceImpl.java.vm";
    private static final String MAPPER_TEMPLATE = "/templates/mapper.java.vm";
    private static final String MAPPER_XML_TEMPLATE = "/templates/mapper.xml.vm";

    private static final String CONTROLLER_TEMPLATE = "/templates/controller.java.vm";

    private static final String CLIENT_TEMPLATE = "/templates/client.java.vm";
    private static final String CLIENT_FALLBACK_TEMPLATE = "/templates/clientFallback.java.vm";

    private static final String SERVICE_TEST_TEMPLATE = "/templates/serviceTest.java.vm";
    private static final String CONTROLLER_TEST_TEMPLATE = "/templates/controllerTest.java.vm";


    /**
     * 文件后缀常量
     */
    private static final String MODEL_SUFFIX = ".java";

    private static final String SERVICE_SUFFIX = "Service.java";
    private static final String SERVICE_IMPL_SUFFIX = "ServiceImpl.java";
    private static final String MAPPER_SUFFIX = "Mapper.java";
    private static final String MAPPER_XML_SUFFIX = "Mapper.xml";

    private static final String CONTROLLER_SUFFIX = "Controller.java";

    private static final String CLIENT_SUFFIX = "Client.java";
    private static final String CLIENT_FALLBACK_SUFFIX = "ClientFallback.java";

    private static final String SERVICE_TEST_SUFFIX = "ServiceImplTest.java";
    private static final String CONTROLLER_TEST_SUFFIX = "ControllerTest.java";


    @SuppressWarnings("all")
    public static List<FileOutParameter> buildOutParmeterList(GeneratorOutputDirConfig generatorOutputDirConfig){

        /**
         * model
         */
        FileOutParameter fileOutParameterModel = new FileOutParameter();
        fileOutParameterModel.setTemplate(MODEL_TEMPLATE);
        fileOutParameterModel.setOutputDir(generatorOutputDirConfig.getModelDir());
        fileOutParameterModel.setFileSuffix(MODEL_SUFFIX);


        /**
         * service
         */
        FileOutParameter fileOutParameterMapper = new FileOutParameter();
        fileOutParameterMapper.setTemplate(MAPPER_TEMPLATE);
        fileOutParameterMapper.setOutputDir(generatorOutputDirConfig.getMapperDir());
        fileOutParameterMapper.setFileSuffix(MAPPER_SUFFIX);

        FileOutParameter fileOutParameterMapperXml = new FileOutParameter();
        fileOutParameterMapperXml.setTemplate(MAPPER_XML_TEMPLATE);
        fileOutParameterMapperXml.setOutputDir(generatorOutputDirConfig.getMapperXmlDir());
        fileOutParameterMapperXml.setFileSuffix(MAPPER_XML_SUFFIX);

        FileOutParameter fileOutParameterService = new FileOutParameter();
        fileOutParameterService.setTemplate(SERVICE_TEMPLATE);
        fileOutParameterService.setOutputDir(generatorOutputDirConfig.getServiceDir());
        fileOutParameterService.setFileSuffix(SERVICE_SUFFIX);

        FileOutParameter fileOutParameterServiceImpl = new FileOutParameter();
        fileOutParameterServiceImpl.setTemplate(SERVICE_IMPL_TEMPLATE);
        fileOutParameterServiceImpl.setOutputDir(generatorOutputDirConfig.getServiceImplDir());
        fileOutParameterServiceImpl.setFileSuffix(SERVICE_IMPL_SUFFIX);

        /**
         * api
         */
        FileOutParameter fileOutParameterController = new FileOutParameter();
        fileOutParameterController.setTemplate(CONTROLLER_TEMPLATE);
        fileOutParameterController.setOutputDir(generatorOutputDirConfig.getControllerDir());
        fileOutParameterController.setFileSuffix(CONTROLLER_SUFFIX);


        /**
         * client
         */
        FileOutParameter fileOutParameterClient = new FileOutParameter();
        fileOutParameterClient.setTemplate(CLIENT_TEMPLATE);
        fileOutParameterClient.setOutputDir(generatorOutputDirConfig.getClientDir());
        fileOutParameterClient.setFileSuffix(CLIENT_SUFFIX);

        FileOutParameter fileOutParameterClientFallback = new FileOutParameter();
        fileOutParameterClientFallback.setTemplate(CLIENT_FALLBACK_TEMPLATE);
        fileOutParameterClientFallback.setOutputDir(generatorOutputDirConfig.getClientFallbackDir());
        fileOutParameterClientFallback.setFileSuffix(CLIENT_FALLBACK_SUFFIX);


        /**
         * test
         */
        FileOutParameter fileOutParameterServiceTest = new FileOutParameter();
        fileOutParameterServiceTest.setTemplate(SERVICE_TEST_TEMPLATE);
        fileOutParameterServiceTest.setOutputDir(generatorOutputDirConfig.getServiceTestDir());
        fileOutParameterServiceTest.setFileSuffix(SERVICE_TEST_SUFFIX);

        FileOutParameter fileOutParameterControllerTest = new FileOutParameter();
        fileOutParameterControllerTest.setTemplate(CONTROLLER_TEST_TEMPLATE);
        fileOutParameterControllerTest.setOutputDir(generatorOutputDirConfig.getControllerTestDir());
        fileOutParameterControllerTest.setFileSuffix(CONTROLLER_TEST_SUFFIX);


        List<FileOutParameter> fileOutParameterList = new ArrayList<>();
        fileOutParameterList.add(fileOutParameterModel);
        fileOutParameterList.add(fileOutParameterMapper);
        fileOutParameterList.add(fileOutParameterMapperXml);
        fileOutParameterList.add(fileOutParameterService);
        fileOutParameterList.add(fileOutParameterServiceImpl);
        fileOutParameterList.add(fileOutParameterController);
        fileOutParameterList.add(fileOutParameterClient);
        fileOutParameterList.add(fileOutParameterClientFallback);
        fileOutParameterList.add(fileOutParameterServiceTest);
        fileOutParameterList.add(fileOutParameterControllerTest);

        return fileOutParameterList;
    }
}
